package she_ji_mo_shi.dan_li.impl;

import she_ji_mo_shi.dan_li.LoadBalancer;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public enum LoadBalancerEnum implements LoadBalancer {
    INSTANCE;
    private final List<String> servers;
    LoadBalancerEnum() {
        servers = new ArrayList<>();
    }
    @Override
    public void addServer(String server) {
        servers.add(server);
    }

    @Override
    public void removeServer(String server) {
        servers.remove(server);
    }

    @Override
    public String getServer() {
        Random random = new Random();
        int i = random.nextInt(servers.size());
        return servers.get(i);
    }
}
